﻿/*****************************************************************
// Copyright (C)
// All rights reserved.
// 
// Author:       WYQ
// Create Date:  2012-8-18 15:16:03
// Usage: 持久化数据库仓库
*****************************************************************/
using System;
using System.Linq;
using System.Linq.Expressions;

namespace Portal.Ef.Repository
{

   
    public class  RecruitmentRepository : Repository<Recruitment, Recruitment, TbRecruitment>, IRecruitmentRepository<Recruitment>
    {
        public override Recruitment CreateEntity()
        {
            return new Recruitment { };
        }
        public override IQueryable<Recruitment> Get()
        {
            return MapQueryable(Entities.TbRecruitment);
        }
        public override long Count()
        {
            return MapQueryable(Entities.TbRecruitment).Count();
        }
        public override IQueryable<Recruitment> Get(Expression<Func<Recruitment, bool>> expression)
        {
            return MapQueryable(Entities.TbRecruitment).Where(expression);
        }
        public override IQueryable<Recruitment> GetSort(string sort = "Id", string order = "DESC")
        {
            Check.Argument.IsNotNull(sort, "排序字段");
            Check.Argument.IsNotNull(order, "排序条件");
            return LinqHelper.DataSorting(MapQueryable(Entities.TbRecruitment), sort, order);
        }
        public override IQueryable<Recruitment> GetSort(Expression<Func<Recruitment, bool>> expression, string sort = "Id", string order = "DESC")
        {
            Check.Argument.IsNotNull(expression, "查询条件");
            Check.Argument.IsNotNull(sort, "排序字段");
            Check.Argument.IsNotNull(order, "排序条件");
            return LinqHelper.DataSorting(MapQueryable(Entities.TbRecruitment).Where(expression), sort, order);
        }
        public override void Add(Recruitment t)
        {
            Entities.AddToTbRecruitment(ReverseMapModel(t));
        }
        public override void Update(Recruitment t)
        {
            throw new NotImplementedException();
        }
        public override void AddOrUpdate(Recruitment t)
        {
            if (Entities.TbRecruitment.Any(o => o.CoRecruitmentId == t.Id))
            {

            }
            else
            {
                Entities.AddToTbRecruitment(ReverseMapModel(t));
            }
        }
        public override void Delete(Recruitment t)
        {
            Entities.TbRecruitment.Where(o => o.CoRecruitmentId == t.Id).ForEach(o => Entities.DeleteObject(o));
        }
        public override void Delete(Expression<Func<Recruitment, bool>> expression)
        {
            MapQueryable(Entities.TbRecruitment).Where(expression).ForEach(o => Entities.DeleteObject(o));
        }
        public override void Save()
        {
            Entities.SaveChanges();
        }
       
        public JqEasyuiDataGrid<Recruitment> JqEasyuiDataGrid(string code, string name, string categoryId, string sort = "CreateTime", string order = "Desc", int page = 10, int index = 1)
        {
            return new JqEasyuiDataGrid<Recruitment>();
        }
      
        public override sealed IQueryable<Recruitment> MapQueryable(IQueryable<TbRecruitment> queryable)
        {
            return queryable.Select(o => new Recruitment 
            {
         
	           Id=o.CoRecruitmentId,
	           Name = o.CoName 
,
	           CreateTime = o.CoCreateTime??DateTime.Now 
,
	           IsDelete = o.CoIsDelete??false 
,
	           Version = o.CoVersion??0 
,
	           IsClosed = o.CoIsClosed??false 
,
	           Culture = o.CoCulture 
,
	           Number = o.CoNumber 
,
	           Degree = o.CoDegree 
,
	           Age = o.CoAge 
,
	           WorkType = o.CoWorkType 
,
	           Workplace = o.CoWorkplace 
,
	           Validity = o.CoValidity 
,
	           WayFor = o.CoWayFor 
,
	           AssessmentMethod = o.CoAssessmentMethod 
,
	           Language = o.CoLanguage 
,
	           WorkExperience = o.CoWorkExperience 
,
	           Sex = o.CoSex 
,
	           MonthlySalaryRange = o.CoMonthlySalaryRange 
,
	           Responsibilities = o.CoResponsibilities 
,
	           OtherTreatment = o.CoOtherTreatment 
,
	           Contact = o.CoContact 
,
	           Telnet = o.CoTelnet 
,
	           Email = o.CoEmail 
,
	           QQ = o.CoQQ 
,
	           Address = o.CoAddress 
            
            });
        }
      
        public override sealed IQueryable<TbRecruitment> ReverseMapQueryable(IQueryable<Recruitment> queryable)
        {
            return queryable.Select(o => new TbRecruitment 
            { 
        
	           CoRecruitmentId=o.Id,
	           CoName = o.Name
,
	           CoCreateTime = o.CreateTime
,
	           CoIsDelete = o.IsDelete
,
	           CoVersion = o.Version
,
	           CoIsClosed = o.IsClosed
,
	           CoCulture = o.Culture
,
	           CoNumber = o.Number
,
	           CoDegree = o.Degree
,
	           CoAge = o.Age
,
	           CoWorkType = o.WorkType
,
	           CoWorkplace = o.Workplace
,
	           CoValidity = o.Validity
,
	           CoWayFor = o.WayFor
,
	           CoAssessmentMethod = o.AssessmentMethod
,
	           CoLanguage = o.Language
,
	           CoWorkExperience = o.WorkExperience
,
	           CoSex = o.Sex
,
	           CoMonthlySalaryRange = o.MonthlySalaryRange
,
	           CoResponsibilities = o.Responsibilities
,
	           CoOtherTreatment = o.OtherTreatment
,
	           CoContact = o.Contact
,
	           CoTelnet = o.Telnet
,
	           CoEmail = o.Email
,
	           CoQQ = o.QQ
,
	           CoAddress = o.Address
  
            
            });
        }
      
        public override sealed Recruitment MapModel(TbRecruitment model)
        {
            return new Recruitment {
	           Id=model.CoRecruitmentId,
	           Name = model.CoName
,
	           CreateTime = model.CoCreateTime??DateTime.Now
,
	           IsDelete = model.CoIsDelete??false
,
	           Version = model.CoVersion??0
,
	           IsClosed = model.CoIsClosed??false
,
	           Culture = model.CoCulture
,
	           Number = model.CoNumber
,
	           Degree = model.CoDegree
,
	           Age = model.CoAge
,
	           WorkType = model.CoWorkType
,
	           Workplace = model.CoWorkplace
,
	           Validity = model.CoValidity
,
	           WayFor = model.CoWayFor
,
	           AssessmentMethod = model.CoAssessmentMethod
,
	           Language = model.CoLanguage
,
	           WorkExperience = model.CoWorkExperience
,
	           Sex = model.CoSex
,
	           MonthlySalaryRange = model.CoMonthlySalaryRange
,
	           Responsibilities = model.CoResponsibilities
,
	           OtherTreatment = model.CoOtherTreatment
,
	           Contact = model.CoContact
,
	           Telnet = model.CoTelnet
,
	           Email = model.CoEmail
,
	           QQ = model.CoQQ
,
	           Address = model.CoAddress
            };
        }
        
        public override sealed TbRecruitment ReverseMapModel(Recruitment model)
        {
            return new TbRecruitment { 
	           CoRecruitmentId=model.Id,
	           CoName = model.Name
	        
,
	           CoCreateTime = model.CreateTime
	        
,
	           CoIsDelete = model.IsDelete
	        
,
	           CoVersion = model.Version
	        
,
	           CoIsClosed = model.IsClosed
	        
,
	           CoCulture = model.Culture
	        
,
	           CoNumber = model.Number
	        
,
	           CoDegree = model.Degree
	        
,
	           CoAge = model.Age
	        
,
	           CoWorkType = model.WorkType
	        
,
	           CoWorkplace = model.Workplace
	        
,
	           CoValidity = model.Validity
	        
,
	           CoWayFor = model.WayFor
	        
,
	           CoAssessmentMethod = model.AssessmentMethod
	        
,
	           CoLanguage = model.Language
	        
,
	           CoWorkExperience = model.WorkExperience
	        
,
	           CoSex = model.Sex
	        
,
	           CoMonthlySalaryRange = model.MonthlySalaryRange
	        
,
	           CoResponsibilities = model.Responsibilities
	        
,
	           CoOtherTreatment = model.OtherTreatment
	        
,
	           CoContact = model.Contact
	        
,
	           CoTelnet = model.Telnet
	        
,
	           CoEmail = model.Email
	        
,
	           CoQQ = model.QQ
	        
,
	           CoAddress = model.Address
	        
            
            
            };
        }


    }
}



